﻿using System.Collections.ObjectModel;

namespace SoulDoorEngine.Framework.Screens
{
    /// <summary>
    /// 继承自抽象类KeyedCollection，特点是Key来自Value的属性
    /// </summary>
    public class ScreenCollection : KeyedCollection<string, Screen>
    {
        protected override string GetKeyForItem(Screen item)
        {
            return item.Name;
        }

        protected override void RemoveItem(int index)
        {
            Screen screen = this.Items[index];

            if (Engine.DefaultScreen == screen)
            {
                Engine.DefaultScreen = Engine.BackgroundScreen;
            }

            base.RemoveItem(index);
        }
    }
}
